/*------------------------------------------------------
                hou_elearningGEN beta v1.0
Author: xtrung.net@gmail.com
Write On: 04/27/2008
Create On:4/13/2012 11:22:56 AM
------------------------------------------------------*/
using hou_elearning.DataAccess.Base;
using hou_elearning.Entity;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections.Generic;
using System.Collections;
using System.Web;

namespace hou_elearning.DataAccess
{    
    public class KhoahocDAL : SqlProvider<KhoahocEntity>
    {
        static KhoahocDAL()
        {
            InitReader();
        }
        protected static void InitReader()
        {
            getFromReader=delegate(SqlDataReader dr)
            {
                KhoahocEntity entity = new KhoahocEntity();
				entity.PK_iKhoahocID = Int64.Parse("0"+dr["PK_iKhoahocID"].ToString());
				entity.sTenkhoahoc = dr["sTenkhoahoc"].ToString();
                entity.sKyhieu = dr["sKyhieu"].ToString();
				entity.sGhichu = dr["sGhichu"].ToString();
				entity.iSoluongdukien = Int16.Parse("0"+dr["iSoluongdukien"].ToString());
                entity.iTrangthai = Int16.Parse("0" + dr["iTrangthai"].ToString());
				entity.dNgaytao =String.IsNullOrEmpty(dr["dNgaytao"].ToString())?DateTime.Now:DateTime.Parse(dr["dNgaytao"].ToString());
				entity.dNgaycapnhat =String.IsNullOrEmpty(dr["dNgaycapnhat"].ToString())?DateTime.Now:DateTime.Parse(dr["dNgaycapnhat"].ToString());
				entity.FK_iNguoitaoID = Int64.Parse("0"+dr["FK_iNguoitaoID"].ToString());
                entity.FK_iNguoicapnhatID = Int64.Parse("0" + dr["FK_iNguoicapnhatID"].ToString());
				entity.sAnhminhhoa = dr["sAnhminhhoa"].ToString();
				entity.FK_iGiangvienID = Int64.Parse("0"+dr["FK_iGiangvienID"].ToString());
				entity.FK_iChungchiID = Int16.Parse("0"+dr["FK_iChungchiID"].ToString());
                return entity;
            };
        }
        public static KhoahocEntity GetOne(Int64 PK_iKhoahocID)
        {
            string cmdName = "spKhoahoc_GetByPK";
            SqlParameter p = new SqlParameter("@PK_iKhoahocID", PK_iKhoahocID);
            KhoahocEntity entity = GetOne(cmdName, p);
            return entity;
        }
        public static List<KhoahocEntity> GetAll()
        {
            string cmdName = "spKhoahoc_Get";
            return GetList(cmdName);
        }
        public static List<KhoahocEntity> GetTopByStatus()
        {
            string cmdName = "spKhoahoc_GetTop";
            return GetList(cmdName);
        }
        public static List<KhoahocEntity> GetTopByTime()
        {
            string cmdName = "spKhoahoc_GetTopOrderByTime";
            return GetList(cmdName);
        }
        public static List<KhoahocEntity> GetByFK_iNguoitaoID(Int64 FK_iNguoitaoID)
		{
			string cmdName = "spKhoahoc_GetByFK_FK_iNguoitaoID";
			SqlParameter p = new SqlParameter("@FK_iNguoitaoID",FK_iNguoitaoID);
			List<KhoahocEntity> list = GetList(cmdName, p);
			return list;
		}
        public static List<KhoahocEntity> GetByFK_iGiangvienID(Int64 FK_iGiangvienID)
		{
			string cmdName = "spKhoahoc_GetByFK_FK_iGiangvienID";
			SqlParameter p = new SqlParameter("@FK_iGiangvienID",FK_iGiangvienID);
			List<KhoahocEntity> list = GetList(cmdName, p);
			return list;
		}public static List<KhoahocEntity> GetByFK_iChungchiID(Int16 FK_iChungchiID)
		{
			string cmdName = "spKhoahoc_GetByFK_FK_iChungchiID";
			SqlParameter p = new SqlParameter("@FK_iChungchiID",FK_iChungchiID);
			List<KhoahocEntity> list = GetList(cmdName, p);
			return list;
		}
        public static int Add(KhoahocEntity entity)
        {
            string cmdName = "spKhoahoc_Insert";
            return Run(cmdName,true,initParams(entity));

        }
        public static bool Edit(KhoahocEntity entity)
        {
            string cmdName = "spKhoahoc_Update";
            return Run(cmdName,false,initParams(entity))>0;
        }
        public static bool Remove(Int64 PK_iKhoahocID)
        {
            string cmdName = "spKhoahoc_Delete";
            SqlParameter p = new SqlParameter("@PK_iKhoahocID", PK_iKhoahocID);
            return Run(cmdName,false,p)>0;
        }
        #region private
        private static SqlParameter[] initParams(KhoahocEntity entity)
        {
            SqlParameter[] p = new SqlParameter[13];
			p[0] = new SqlParameter("@PK_iKhoahocID", entity.PK_iKhoahocID);
			p[1] = new SqlParameter("@sTenkhoahoc", entity.sTenkhoahoc);
            p[2] = new SqlParameter("@sKyhieu", entity.sKyhieu);
			p[3] = new SqlParameter("@sGhichu", entity.sGhichu);
			p[4] = new SqlParameter("@iSoluongdukien", entity.iSoluongdukien);
			p[5] = new SqlParameter("@dNgaytao", entity.dNgaytao);
			p[6] = new SqlParameter("@dNgaycapnhat", entity.dNgaycapnhat);
			p[7] = new SqlParameter("@FK_iNguoitaoID", entity.FK_iNguoitaoID);
			p[8] = new SqlParameter("@sAnhminhhoa", entity.sAnhminhhoa);
			p[9] = new SqlParameter("@FK_iGiangvienID", entity.FK_iGiangvienID);
			p[10] = new SqlParameter("@FK_iChungchiID", entity.FK_iChungchiID);
            p[11] = new SqlParameter("@FK_iNguoicapnhatID", entity.FK_iNguoicapnhatID);
            p[12] = new SqlParameter("@iTrangthai", entity.iTrangthai);
            return p;
        }
        #endregion
       
    }
}